package com.pmsystem.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pmsystem.pojo.Office;
import com.pmsystem.service.OfficeService;


/**
 * 
* <p>Title: OfficeController</p>  
* <p>Description:办公室信息的控制器 </p>  
* @author 树昌  
* @date 2019年1月24日
 */
@Controller
@RequestMapping("office/")
public class OfficeController {

	@Autowired
	OfficeService officeService;
	
	/**
	 * 
	 * <p>Title: addOffice</p>  
	 * <p>Description:添加一条办公室的记录 </p>  
	 * @author 树昌
	 * @param office
	 * @return 跳转到显示办公室信息的页面
	 */
	@RequestMapping(value="addoffice",method=RequestMethod.POST)
	public String addOffice(Office office) {
		boolean row = officeService.addOffice(office);
		if(row) {
			return "office/showoffice";
		}else {
			return "error";
		}
	}
	
	
	/**
	 * 
	 * <p>Title: showOffice</p>  
	 * <p>Description:查询办公室信息的记录 </p>  
	 * @author 树昌
	 * @param keyword	搜索关键词
	 * @param startRow	页码
	 * @param pageSize	每页显示记录的条数
	 * @return	不做跳转
	 */
	@RequestMapping(value="showoffice",method=RequestMethod.POST)
	@ResponseBody
	public List<Office> showOffice(String keyword, Integer startRow, Integer pageSize){
		return officeService.showOffice(keyword, startRow, pageSize);
	}
	
	
	
	/**
	 * 
	 * <p>Title: deleteOffice</p>  
	 * <p>Description:删除一条办公室记录的控制器 </p>  
	 * @author 树昌
	 * @param office
	 * @return 不做跳转
	 */
	@RequestMapping(value="deleteoffice",method=RequestMethod.POST)
	@ResponseBody
	public void deleteOffice(Office office){
		
		officeService.deleteOffice(office);
	}
	
	
	@RequestMapping(value="updateoffice",method=RequestMethod.POST)
	public String updateOffice(Office office) {
		
		boolean row = officeService.updateOffice(office);
		if(row) {
			return "office/showoffice";
		}else {
			return "error";
		}
	}
	
	
}